<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script>
    var ctx = null
    var offset = 0
    function draw() {
      ctx.clearRect(0, 0, canvas.width, canvas.height)
      ctx.setLineDash([4,2])
      ctx.lineDashOffset = -offset
      ctx.strokeRect(10, 10, 100, 100)
    }
    function match() {
      offset++
      if (offset > 16) {
        offset = 0
      }
      draw()
      setTimeout(match, 60)
    }
    window.onload = function() {
      ctx = document.getElementById('canvas').getContext('2d')
      match()
    }
  </script>
</head>
<body>
  <canvas id="canvas" width="150" height="150"></canvas>
</body>
</html>